package com.cn.hnust.service.impl;  
  


import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import com.cn.hnust.common.Page;
import com.cn.hnust.dao.IUserDao;
import com.cn.hnust.pojo.User;
import com.cn.hnust.service.IUserService;  
  
@Service("userService")  
public class UserServiceImpl implements IUserService {  
    @Resource  
    private IUserDao userDao;  
    @Override  
    public User getUserById(int userId) {  
        // TODO Auto-generated method stub  
        return this.userDao.selectByPrimaryKey(userId);  
    }
    @Override  
    public void showProductsByPage(HttpServletRequest request, Model model) {  
        String pageNow = request.getParameter("pageNow");  
      
        Page page = null;  
      
        List<User> products = new ArrayList<User>();  
      
        int totalCount = (int) userDao.getProductsCount();  
      
        if (pageNow != null) {  
            page = new Page(totalCount, Integer.parseInt(pageNow));  
            products = this.userDao.selectProductsByPage(page.getStartPos(), page.getPageSize());  
        } else {  
            page = new Page(totalCount, 1);  
            products = this.userDao.selectProductsByPage(page.getStartPos(), page.getPageSize());  
        }  
      
        model.addAttribute("products", products);  
        model.addAttribute("page", page);  
    } 
    @Override
    public int adduser(User uinfo){
    	return this.userDao.insert(uinfo);
    }
    @Override
    public int deleteuser(int id){
    	return this.userDao.deleteByPrimaryKey(id);
    }
    @Override
    public int updateuser(User record){
    	return this.userDao.updateByPrimaryKey(record);
    }
  
}  
